package com.sinoglobal.wallet.adapter;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sinoglobal.wallet.R;
import com.sinoglobal.wallet.entity.W_RechargeRecordItemEntity;
import com.sinoglobal.wallet.entity.W_RechargeRecordItemRsEntity;

public class W_RechargeRecordAdapter extends W_SinoBaseSimpleAdapter<W_RechargeRecordItemRsEntity>{

	public W_RechargeRecordAdapter(Context mContext) {
		super(mContext);
	}

	@Override
	public void findViews(Map<java.lang.String, View> widgets, int position, View convertView) {
		TextView recharg_record_title = (TextView) convertView.findViewById(R.id.recharg_record_title);
		TextView recharg_record_time = (TextView) convertView.findViewById(R.id.recharg_record_time);
		TextView recharg_record_money = (TextView) convertView.findViewById(R.id.recharg_record_money);
		TextView recharg_record_state = (TextView) convertView.findViewById(R.id.recharg_record_state);
		LinearLayout rechrecord_list_item_indexlayout = (LinearLayout) convertView.findViewById(R.id.rechrecord_list_item_indexlayout);
		widgets.put("recharg_record_title", recharg_record_title);
		widgets.put("recharg_record_time", recharg_record_time);
		widgets.put("recharg_record_money", recharg_record_money);
		widgets.put("recharg_record_state", recharg_record_state);
		widgets.put("rechrecord_list_item_indexlayout", rechrecord_list_item_indexlayout);
	}
	

	@Override
	public void setValues(View convertView, ViewHolder holder, Map<String, View> widgets, int position) {
		TextView recharg_record_title = (TextView) widgets.get("recharg_record_title");
		TextView recharg_record_time = (TextView) widgets.get("recharg_record_time");
		TextView recharg_record_money = (TextView) widgets.get("recharg_record_money");
		TextView recharg_record_state = (TextView) widgets.get("recharg_record_state");
		LinearLayout rechrecord_list_item_indexlayout = (LinearLayout) widgets.get("rechrecord_list_item_indexlayout");
		if(position==0){
			rechrecord_list_item_indexlayout.setVisibility(View.VISIBLE);
			
		}else{
			rechrecord_list_item_indexlayout.setVisibility(View.GONE);
		}
		W_RechargeRecordItemRsEntity recharg_record = (W_RechargeRecordItemRsEntity) getItem(position);
		  SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd  HH:mm:ss");  
		  recharg_record_time.setText(sdf.format(new Date(recharg_record.getCreateDate())));
		
	    recharg_record_money.setText(recharg_record.getAmount()+"元");
	
	    if("1".equals(recharg_record.getPayType())){  //1：余额、2：支付宝、3：U付、4：微信
	    	recharg_record_title.setText("余额");
	    }else if("2".equals(recharg_record.getPayType())){
	    	recharg_record_title.setText("支付宝");
	    }else if("3".equals(recharg_record.getPayType())){
	    	recharg_record_title.setText("借记卡");
	    }else if("4".equals(recharg_record.getPayType())){
	    	recharg_record_title.setText("微信");
	    }
	    //支付状态:1:成功 2:失败 3:待支付 4:充值中
		if("1".equals(recharg_record.getPayStatus())){
			recharg_record_money.setTextColor(mContext.getResources().getColor(R.color.w_payPass_gray));
			recharg_record_state.setTextColor(mContext.getResources().getColor(R.color.w_payPass_gray));
		
			recharg_record_state.setText("成功");
			     
		}else if("2".equals(recharg_record.getPayStatus())){
			recharg_record_money.setTextColor(mContext.getResources().getColor(R.color.w_payPass_gray));
			recharg_record_state.setTextColor(mContext.getResources().getColor(R.color.w_payPass_gray));
			recharg_record_state.setText("失败");
		}else if("3".equals(recharg_record.getPayStatus())){
			recharg_record_money.setTextColor(mContext.getResources().getColor(R.color.w_red_color2));
			recharg_record_state.setTextColor(mContext.getResources().getColor(R.color.w_red_color2));
			recharg_record_state.setText("待充值");
		}else if("4".equals(recharg_record.getPayStatus())){
			recharg_record_money.setTextColor(mContext.getResources().getColor(R.color.w_yellow_color));
			recharg_record_state.setTextColor(mContext.getResources().getColor(R.color.w_yellow_color));
			recharg_record_state.setText("充值中");
		}else if("5".equals(recharg_record.getPayStatus())){
			recharg_record_money.setTextColor(mContext.getResources().getColor(R.color.w_payPass_gray));
			recharg_record_state.setTextColor(mContext.getResources().getColor(R.color.w_payPass_gray));
			recharg_record_state.setText("已关闭");
		}
	
	}

	@Override
	public View setAdapterLayout(LayoutInflater inflater, int position) {
		return inflater.inflate(R.layout.wallet_rechrecord_list_item_layout, null);
	}
	
}
